<template>
	<view class="container" :class="skinStyle">
		<scroll-view class="top-tabs-view" scroll-x="true" :scroll-left="scrollLeft">
			<progress v-if="progressFlg" percent="100" activeColor="#e83f0a" active stroke-width="1" duration="5" class="progress" />
			<block v-for="(tab, index) in tabs" :key="index">
				<view class="tabs-item-wrap" v-bind:id="'tabNum' + index" @click="swichMenu(index)">
					<view class="tabs-item" :class="[currentTab == index ? 'tabs-item-act' : '']">
						<view class="tabs-item-txt">{{ tab.name }}</view>
						<view class="tabs-item-bottom"></view>
					</view>
				</view>
			</block>
		</scroll-view>

		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" :up="upOption" @up="upCallback" :fixed="true">
			<view class="tui-order-list">
				<view class="tui-order-item" v-for="(order, orderIndex) in orderList" :key="orderIndex">
					<view>
						<tui-list-cell :hover="false" :lineLeft="false">
							<view class="tui-goods-title">
								<view>订单号：{{ order.orderId }}</view>
								<view
									class="tui-order-status theme-color"
									v-if="order.productInfo[0].preSaleFlag == 1 && order.orderPreSaleStatus != 3&&order.orderStatus!=70"
									v-html="getPreStatus(order.orderPreSaleStatus)"
								></view>
								<view class="tui-order-status theme-color" v-else v-html="getStatusLabel(order.orderStatus)"></view>
							</view>
						</tui-list-cell>
						<view v-for="(item, index) in order.productInfo" :key="index">
							<block v-if="item.show !== 2">
								<!-- <tui-list-cell padding="0" class="b-bottom-none"> -->
								<view class="tui-goods-item" @tap="detail(order.orderId)">
									<image src="../../../static/img/freeShipping.png" class="tui-goods-img imgMark" v-if="item.isSample === 0 && item.isParcel === 1"></image>
									<image src="../../../static/img/gift.png" class="imgMark" v-if="item.isSample !== 0"></image>
									<image :src="imgSrc + item.suitProductThumbnailImageUrl" v-if="item.isSuit" class="tui-goods-img"></image>
									<image :src="imgSrc + item.productThumbnailImageUrl" v-else class="tui-goods-img"></image>
									<view class="tui-goods-center">
										<view class="tui-goods-name" v-if="item.isSuit">{{ item.suitName }}</view>
										<view class="tui-goods-name" v-else>{{ item.productName }}</view>
										<view class="tui-goods-attr" v-if="item.isSuit"></view>
										<view class="tui-goods-attr" v-else>{{ item.specificationName }}</view>
									</view>
									<view class="tui-price-right">
										<view v-if="item.isSuit">￥{{ (item.suitRealAmount / item.suitCount) | moneyFormat(item.suitRealAmount / item.suitCount) || '0' }}</view>
										<view v-else>￥{{ (item.realAmount / item.productsCount) | moneyFormat(item.realAmount / item.productsCount) || '0' }}</view>
										<view v-if="item.isSuit">x{{ item.suitCount }}</view>
										<view v-else>x{{ item.productsCount }}</view>
									</view>
								</view>

								<!-- </tui-list-cell> -->
								<view :class="{ 'b-bottom': index != order.productInfo.length - 1 - item.suitNum }">
									<view class="tui-order-btn">
										<view class="tui-btn-ml" v-if="item.suitId && !item.suitShow" @tap="changeSuitShow(item)">
											<tui-button type="black" :plain="true" width="160rpx" height="62rpx" :size="28" shape="circle">展开</tui-button>
										</view>
										<view class="tui-btn-ml" v-if="item.suitId && item.suitShow" @tap="changeSuitShow(item)">
											<tui-button type="black" :plain="true" width="160rpx" height="62rpx" :size="28" shape="circle">收起</tui-button>
										</view>
										<view class="tui-btn-ml" v-if="order.orderStatus != 0 && item.isSample == 0">
											<tui-button type="primary" :plain="true" width="160rpx" height="62rpx" :size="28" shape="circle" @tap="productDetail(item)">
												再次购买
											</tui-button>
										</view>
									</view>
									<view class="suitItem" v-if="item.suitShow">
										<view class="tui-goods-item suitProduct" v-for="(item2, index2) in item.suitInfo" :key="index2">
											<image :src="imgSrc + item2.productThumbnailImageUrl" class="tui-goods-img"></image>
											<view class="tui-goods-center">
												<view class="tui-goods-name">{{ item2.productName }}</view>
											</view>
											<view class="tui-price-right">
												<view>x{{ item2.productsCount }}</view>
											</view>
										</view>
									</view>
								</view>
							</block>
						</view>
						<view class="b-bottom">
							<tui-list-cell :hover="false" :last="true">
								<view class="tui-goods-price ">
									<view>运费：</view>
									<view class="tui-size-24 price-color">￥</view>
									<view class="tui-price-large price-color">{{ order.logisticsCost }}</view>
								</view>
							</tui-list-cell>
						</view>
						<tui-list-cell :hover="false" :last="true" class="b-bottom-none">
							<view class="tui-goods-price">
								<view>共{{ order.orderCount }}件商品 合计：</view>
								<view class="tui-size-24 price-color">￥</view>
								<view class="tui-price-large price-color">{{ order.realAmount }}</view>
							</view>
						</tui-list-cell>
					</view>
					<view class="tui-order-btn">
						<view class="tui-btn-ml" v-if="order.orderStatus == 0 && order.orderPreSaleStatus != 2 && order.orderPreSaleStatus != 1">
							<tui-button type="black" :plain="true" width="160rpx" height="62rpx" :size="28" shape="circle" @tap="show('1', order.orderId)">取消订单</tui-button>
						</view>
						<view class="tui-btn-ml" v-if="order.orderStatus == 0 && order.orderPreSaleStatus != 2">
							<tui-button type="primary" :plain="true" width="160rpx" height="62rpx" :size="28" shape="circle" @tap="pay(order)">去付款</tui-button>
						</view>
						<view class="tui-btn-ml" v-else-if="order.orderStatus == 0 && order.orderPreSaleStatus == 2 && timeLimit(order)">
							<tui-button type="primary" :plain="true" width="160rpx" height="62rpx" :size="28" shape="circle" @tap="pay(order)">去付款</tui-button>
						</view>
						<view class="tui-btn-ml" v-if="order.orderStatus != 70 && order.orderStatus != 0 && order.orderStatus != 100 && checkReturn(order)">
							<tui-button type="black" :plain="true" width="160rpx" height="62rpx" :size="28" shape="circle" @tap="applyService(order)">申请售后</tui-button>
						</view>
						<view
							class="tui-btn-ml"
							v-if="order.orderStatus == 30 || order.orderStatus == 40 || order.orderStatus == 50 || order.orderStatus == 60 || order.orderStatus == 90"
						>
							<tui-button type="black" :plain="true" width="160rpx" height="62rpx" :size="28" shape="circle" @tap="getLogistics(order.orderId)">查看物流</tui-button>
						</view>

						<view class="tui-btn-ml" v-if="order.orderStatus == 30">
							<tui-button type="primary" :plain="true" width="160rpx" height="62rpx" :size="28" shape="circle" @tap="show('2', order.orderId)">确认收货</tui-button>
						</view>
						<!-- v-if="order.orderStatus == 40" -->
						<view class="tui-btn-ml" v-if="order.orderStatus == 40">
							<tui-button type="primary" :plain="true" width="160rpx" height="62rpx" :size="28" shape="circle" @tap="appraise(order, '0')">去评价</tui-button>
						</view>
						<!-- v-if="order.orderStatus == 60" -->
						<view class="tui-btn-ml" v-if="order.orderStatus == 60 && order.addCommentFlg == 0">
							<tui-button type="primary" :plain="true" width="160rpx" height="62rpx" :size="28" shape="circle" @tap="appraise(order, '1')">追加评价</tui-button>
						</view>
					</view>
				</view>
			</view>
		</mescroll-body>
		<tui-modal :show="modalShow" @click="handleClick" @cancel="hide" title="提示" :content="modalContent"></tui-modal>
		<!-- <loading></loading> -->
		<tui-modal></tui-modal>
	</view>
</template>

<script>
import tuiTabs from '@/packageA/components/tui-tabs/tui-tabs';
import tuiButton from '@/components/button/button';
import tuiLoadmore from '@/components/loadmore/loadmore';
import tuiNomore from '@/components/nomore/nomore';
import tuiListCell from '@/components/list-cell/list-cell';
import tuiSticky from '@/packageA/components/sticky/sticky';
import mixin from '@/utils/mixin.js';
import MescrollMixin from '@/components/mescroll-uni/mescroll-mixins.js';
export default {
	mixins: [mixin, MescrollMixin],
	components: {
		tuiTabs,
		tuiButton,
		tuiLoadmore,
		tuiNomore,
		tuiListCell,
		tuiSticky
	},
	data() {
		return {
			imgSrc: this.$store.state.imgUrl,
			isLoading: false,
			progressFlg: true,
			scrollLeft: 0,
			currentTab: 0,
			tabs: [
				{
					name: '全部'
				},
				{
					name: '待付款'
				},
				{
					name: '待发货'
				},
				{
					name: '待收货'
				},
				{
					name: '待评价'
				}
			],
			orderList: [], //订单列表
			postSaleList: [], //退款、售后列表
			modalShow: false,
			modalContent: '',
			upOption: {
				noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
				textNoMore: '-- 无更多信息 --'
			},
			mescroll: null,
			postSaleMode: ['退款', '售后'],
			cancelPostSale: '1', //'1'撤销申请，'2'表示放弃申请
			currentPostSaleId: '',
			currentVersion: 0,
			searchKey: '',
			dialogFlag: '',
			orderId: '',
			stopFunctionArr: [],
		};
	},
	onLoad(options) {
		// #ifdef H5
		this.$wechat.noShare();
		// #endif
		if (options.tabIndex) {
			this.currentTab = Number(options.tabIndex);
			this.setScrollLeft(this.currentTab);
		} else {
			this.currentTab = 0;
		}
		this.stopFunctionArr = this.$store.state.dictDataAll['stopFunction'];
	},
	mounted() {
		// 监听页面刷新
		this.$eventHub.$off('orderRefresh');
		this.$eventHub.$on('orderRefresh', () => {
			this.mescroll.resetUpScroll();
		});
	},
	filters: {
		moneyFormat(num) {
			var result = parseFloat(num);
			result = Math.round(num * 100) / 100;
			var s_x = result.toString();
			var pos_decimal = s_x.indexOf('.');
			if (pos_decimal < 0) {
				pos_decimal = s_x.length;
				s_x += '.';
			}
			while (s_x.length <= pos_decimal + 2) {
				s_x += '0';
			}
			return s_x;
		},
		mathFloor(num) {
			var num1 = parseFloat(num).toFixed(3);
			var result = Math.floor(num1 * 100) / 100;
			if (result < 0.01) {
				result = 0.01;
			}
			return result;
		}
	},
	methods: {
		moneyFormat(num) {
			var result = parseFloat(num);
			result = Math.round(num * 100) / 100;
			return result;
		},
		changeSuitShow(item) {
			item.suitShow = !item.suitShow;
		},
		checkReturn(list) {
			let array = [];
			let num = 0;
			let isSample = 0;
			if (list.acceptDate) {
				const acceptDate = this.getUnixTime(list.acceptDate) + 604800;
				const nowDate = this.getUnixTime(list.nowDate);
				if (acceptDate < nowDate) {
					return false;
				}
			}
			list.productInfo.forEach((item, index) => {
				let multiple = 1;
				item.isRefund = false;
				item.remain = item.productsCount;
				if (item.suitCount) {
					multiple = parseInt(item.productsCount / item.suitCount);
				}
				let arr = [0];

				list.rejectInfo.forEach((item2, index) => {
					arr.push(item2.rejectNo);
					if (item2.customerServiceStatus !== 0 && item2.customerServiceStatus !== 9 && item2.customerServiceStatus !== 11) {
						if (item.isSample !== 0) {
							isSample += 1;
						}
						if (item.orderProductId == item2.orderProductId) {
							item.remain -= item2.productsCount;
							if (item.remain <= 0) {
								num += 1;
								item.isRefund = true;
							} else {
								item.isRefund = false;
							}
						}
					}
				});
				item.maxRejectNo = Math.max(...arr);
				if (item.suitCount) {
					item.remain = parseInt(item.remain / multiple);
				}
			});
			if (isSample > 0) {
				return false;
			}
			if (num === list.productInfo.length) {
				return false;
			} else {
				return true;
			}
		},
		/*下拉刷新的回调, 有三种处理方式:*/
		// downCallback(){
		// 	// this.mescroll.num = 1;
		// 	// this.upCallback(mescroll);
		// },
		/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
		timeLimit(item) {
			if (item.preSaleAfterPaymentStartTime && item.nowDate) {
				const startTime = this.getUnixTime(item.preSaleAfterPaymentStartTime);
				const now = this.getUnixTime(item.nowDate);
				if (startTime > now) {
					return false;
				} else {
					return true;
				}
			} else {
				return true;
			}
		},
		appraise(item, type) {
			let stopFunItem1 = null; //当前对象
			let stopFunItem2 = null; //message对象
			let stopFunItemArr = this.stopFunctionArr.filter((item) => {
				return (item.dictLabel == 'function5' || item.dictLabel == 'message')
			});
			if (stopFunItemArr[0].dictLabel == 'function5') {
				stopFunItem1 = stopFunItemArr[0];
				stopFunItem2 = stopFunItemArr[1];
			} else {
				stopFunItem2 = stopFunItemArr[0];
				stopFunItem1 = stopFunItemArr[1];
			}
			if (stopFunItem1.dictValue == '0') { //开启
				var itemData = JSON.parse(JSON.stringify(item));
				console.log(itemData);
				uni.navigateTo({
					url: './evaluate?order=' + item.orderId + '&type=' + type
				});
			
			} else { //关闭
				let titleTips = stopFunItem2.dictValue
				uni.showToast({
					icon: 'none',
					title: titleTips,
					duration: 2000,
				})
			}
			
		},
		getUnixTime(dateStr) {
			var newstr = dateStr.replace(/-/g, '/');
			var date = new Date(newstr);
			var time_str = date.getTime().toString();
			return parseInt(time_str.substr(0, 10));
		},
		upCallback(page) {
			const params = {
				orderStatus: this.getStatusParams(this.currentTab), //0:全部 1：待付款 2：待发货 3：待收货 4：待评价
				pageSize: page.size,
				current: page.num
			};

			this.$http
				.getOrderList(params)
				.then(res => {
					if (res.status == 0) {
						this.progressFlg = false;
						let dataTemp = [];
						dataTemp = res.data.records;
						dataTemp.forEach((item, index2) => {
							let suitIdArr = [];
							let index = [];
							for (let i = 0; i < item.productInfo.length; i += 1) {
								item.productInfo[i].suitNum = 0;
								if (item.productInfo[i].suitId) {
									let id = item.productInfo[i].suitId + item.productInfo[i].isSample;
									if (id != null && !suitIdArr.includes(id)) {
										item.productInfo[i].suitInfo = [];
										item.productInfo[i].once = parseInt(item.productInfo[i].productsCount / item.productInfo[i].suitCount);
										item.productInfo[i].suitInfo.push({
											productThumbnailImageUrl: JSON.parse(JSON.stringify(item.productInfo[i].productThumbnailImageUrl)),
											productName: JSON.parse(JSON.stringify(item.productInfo[i].productName)),
											productsCount: JSON.parse(JSON.stringify(item.productInfo[i].once))
										});
										item.productInfo[i].isSuit = true;
										index.push({
											suitId: id,
											index: i
										});
										item.productInfo[i].suitRealAmount = JSON.parse(JSON.stringify(item.productInfo[i].realAmount));
										item.productInfo[i].suitShow = false;
										item.productInfo[i].suitNum += 1;
										item.productInfo[i].suitRejectAmount = JSON.parse(JSON.stringify(item.productInfo[i].detailRejectAmount));
										suitIdArr.push(id);
									} else if (id != null && suitIdArr.includes(id)) {
										let n = 0;
										for (let j = 0; j < index.length; j += 1) {
											if (index[j].suitId === id) {
												n = index[j].index;
											}
										}
										item.productInfo[i].once = parseInt(item.productInfo[i].productsCount / item.productInfo[i].suitCount);
										item.productInfo[n].suitInfo.push({
											productThumbnailImageUrl: JSON.parse(JSON.stringify(item.productInfo[i].productThumbnailImageUrl)),
											productName: JSON.parse(JSON.stringify(item.productInfo[i].productName)),
											productsCount: JSON.parse(JSON.stringify(item.productInfo[i].once))
										});
										item.productInfo[n].suitRealAmount += item.productInfo[i].realAmount;
										item.productInfo[n].suitRejectAmount += item.productInfo[i].detailRejectAmount
										item.productInfo[i].suitNum += 1;
										item.productInfo[i].show = 2;
										
									}
								}
							}
						});
						console.log(dataTemp);
						this.mescroll.endSuccess(dataTemp.length);
						if (page.num === 1) {
							// 如果是第一页需手动制空列表
							this.orderList = [];
							this.mescroll.scrollTo(0, 0);
						}
						console.log(dataTemp);
						this.orderList = this.orderList.concat(dataTemp);
					}
				})
				.catch(() => {
					this.mescroll.endErr();
				});
		},
		dataShaping(list) {
			let productList = [];
			list.forEach((item, index) => {
				if (item.suitId !== '' && item.suitId !== null) {
					const suitRow = list.filter(item2 => item.suitId === item2.suitId);
				} else {
					productList.push(item);
				}
			});
		},
		getRefundInfo(item) {
			if (item.rejectInfo) {
				if (item.rejectInfo.length == 0) {
					return true;
				} else {
					let num = 0;
					for (let i = 0; i < item.rejectInfo.length; i += 1) {
						if (item.rejectInfo[0].rejectStatus == 1 || item.rejectInfo[0].rejectStatus == 2 || item.rejectInfo[0].rejectStatus == 14) {
							num += 1;
						}
					}
					if (num == 0) {
						return true;
					} else {
						return false;
					}
				}
			} else {
				return true;
			}
		},
		getStatusParams(id) {
			switch (id) {
				case 0:
					return '';
				case 1:
					return '0';
				case 2:
					return '10';
				case 3:
					return '30';
				case 4:
					return '40';
				default:
					return '';
			}
		},
		getStatusLabel(id) {
			switch (id) {
				case 0:
					return '待付款';
				case 10:
					return '待发货';
				case 30:
					return '待收货';
				case 40:
					return '待评价';
				case 50:
					return '部分退款';
				case 60:
					return '已评价';
				case 70:
					return '交易已取消';
				case 90:
					return '订单退款';
				case 100:
					return '待发货';
				default:
					return '';
			}
		},
		getPreStatus(id) {
			switch (id) {
				case 1:
					return '待付定金';
				case 2:
					return '待付尾款';
				default:
					return '';
			}
		},
		getLogistics(id) {
			uni.navigateTo({
				url: '../logistics/logistics?orderId=' + id
			});
		},
		show(tag, orderId) {
			//tag 为'1'表示撤销申请，'2'表示放弃申请，
			if (tag == '1') {
				let stopFunItem1 = null; //当前对象
				let stopFunItem2 = null; //message对象
				let stopFunItemArr = this.stopFunctionArr.filter((item) => {
					return (item.dictLabel == 'function2' || item.dictLabel == 'message')
				});
				if (stopFunItemArr[0].dictLabel == 'function2') {
					stopFunItem1 = stopFunItemArr[0];
					stopFunItem2 = stopFunItemArr[1];
				} else {
					stopFunItem2 = stopFunItemArr[0];
					stopFunItem1 = stopFunItemArr[1];
				}
				
				if (stopFunItem1.dictValue == '0') { //开启
					this.modalShow = true;
					this.modalContent = '您确定要取消订单吗？';
					this.dialogFlag = '1';
				} else { //关闭
					let titleTips = stopFunItem2.dictValue
					uni.showToast({
						icon: 'none',
						title: titleTips,
						duration: 2000,
					})
				}
			} else if (tag == '2') {
				this.modalShow = true;
				this.modalContent = '您确定要收货吗？';
				this.dialogFlag = '2';
			}
			this.orderId = orderId;
		},

		handleClick(e) {
			let index = e.index;

			//撤销申请，放弃申请
			if (index == 1) {
				this.isLoading = true;
				var that = this;
				if (that.dialogFlag == '1') {
					let params = {
						orderId: this.orderId,
						orderStatus: 70
					};
					that.$http.editOrder(params).then(res => {
						if (res.status == 0) {
							uni.showToast({
								title: '取消成功!',
								icon: 'none'
							});
							that.mescroll.resetUpScroll();
						}
						this.isLoading = false;
					});
				} else if (that.dialogFlag == '2') {
					let params = {
						orderId: this.orderId,
						orderStatus: 40
					};
					that.$http.editOrder(params).then(res => {
						if (res.status == 0) {
							uni.showToast({
								title: '收货成功!',
								icon: 'none'
							});
							that.mescroll.resetUpScroll();
						}
						this.isLoading = false;
					});
				}
			}
			this.hide();
		},
		hide() {
			this.modalShow = false;
		},
		getPostStatus: function(mode, status) {
			let html = this.postSaleMode[Number(mode) - 1] + '-' + this.postSaleStatus[Number(status) - 1];
			return html;
		},
		getStatus: function(status, orderCancelFlg) {
			if (orderCancelFlg) {
				return ['待支付', '退款中', '备货中', '待提货', '已完成', '已取消', '退款', '售后'][status - 1];
			} else {
				return ['待支付', '已支付', '备货中', '待提货', '已完成', '已取消', '退款', '售后'][status - 1];
			}
		},
		applyService(order2) {
			let stopFunItem1 = null; //当前对象
			let stopFunItem2 = null; //message对象
			let stopFunItemArr = this.stopFunctionArr.filter((item) => {
				return (item.dictLabel == 'function4' || item.dictLabel == 'message')
			});
			if (stopFunItemArr[0].dictLabel == 'function4') {
				stopFunItem1 = stopFunItemArr[0];
				stopFunItem2 = stopFunItemArr[1];
			} else {
				stopFunItem2 = stopFunItemArr[0];
				stopFunItem1 = stopFunItemArr[1];
			}
			
			if (stopFunItem1.dictValue == '0') { //开启
				console.log(order);
				let order = JSON.parse(JSON.stringify(order2));
				let productInfo = [];
				let refundflag = false;
				if (order.orderStatus == 10) {
					refundflag = true;
				}
				for (let j = 0; j < order.productInfo.length; j += 1) {
					if (order.productInfo[j].isSample !== 0) {
						refundflag = true;
					}
				}
				for (let i = 0; i < order.productInfo.length; i += 1) {
					if (!order.productInfo[i].isRefund) {
						if (refundflag) {
							order.productInfo[i].disabled = true;
						} else {
							order.productInfo[i].disabled = false;
						}
						order.productInfo[i].checked = true;
						order.productInfo[i].singleCount = JSON.parse(JSON.stringify(order.productInfo[i].productsCount))
						if (order.productInfo[i].realAmount) {
							
							let num1 =this.moneyFormat(order.productInfo[i].realAmount / order.productInfo[i].productsCount);
							if(order.productInfo[i].remain==1){
								num1 = this.moneyFormat(order.productInfo[i].realAmount- order.productInfo[i].detailRejectAmount)
							}
							if (num1 < 0.01) {
								num1 = 0.01;
							}
							order.productInfo[i].productRealPrice = num1;
						} else {
							order.productInfo[i].productRealPrice = 0.0;
						}
						if (order.productInfo[i].suitRealAmount) {
							let num2 = this.moneyFormat(order.productInfo[i].suitRealAmount / order.productInfo[i].suitCount);
							
							if(order.productInfo[i].remain==1){
								num2 = this.moneyFormat(order.productInfo[i].suitRealAmount - order.productInfo[i].suitRejectAmount)
							}
							if (num2 < 0.01) {
								num2 = 0.01;
							}
							order.productInfo[i].suitRealPrice = num2;
						}else{
							order.productInfo[i].suitRealPrice = 0.0;
						}
						productInfo.push(order.productInfo[i]);
					}
				}
				order.productInfo = JSON.parse(JSON.stringify(productInfo));
				uni.setStorageSync('returnOrder', order);
				uni.navigateTo({
					url: '../orderReturn/selectService?item=creat&status=' + order.orderStatus
				});
			} else { //关闭
				let titleTips = stopFunItem2.dictValue
				uni.showToast({
					icon: 'none',
					title: titleTips,
					duration: 2000,
				})
			}
		},
		detail(id) {
			//tag为'1'表示普通订单，tag为'2'退款/售后
			uni.navigateTo({
				url: '../orderDetail/orderDetail?&id=' + id
			});
		},
		productDetail(item) {
			if (item.suitId) {
				uni.navigateTo({
					url: '../goodsDetails/goodsDetails?&suitId=' + item.suitId
				});
			} else {
				uni.navigateTo({
					url: '../goodsDetails/goodsDetails?&productId=' + item.productId
				});
			}
		},
		getAfterPaymentTime(item, endTime, list) {
			if (list.orderPreSaleStatus == 1) {
				return this.getbalanceTime(list);
			} else {
				if (item.preSaleAfterPaymentDateType === 1) {
					return `请在${this.changeTime(endTime)}之前支付尾款`;
				} else {
					return `请在${this.changeTime(item.preSaleAfterPaymentFixedEndTime)}之前支付尾款`;
				}
			}
		},
		getbalanceTime(list) {
			if (list.productInfo[0].preSaleAfterPaymentDateType == 1) {
				if (list.productInfo[0].preSaleAfterPaymentStartDay) {
					return '付定金' + list.productInfo[0].preSaleAfterPaymentStartDay + '天后开始';
				} else {
					return '付定金后';
				}
			} else {
				return list.productInfo[0].preSaleAfterPaymentFixedStartTime + '之后开始';
			}
		},
		deliveryTime(list) {
			if (list.preSaleDeliveryTimeText.indexOf('年') == -1) {
				return list.preSaleDeliveryTimeText;
			} else {
				return list.preSaleDeliveryTimeText.split('年')[1];
			}
		},
		changeTime(time) {
			const date = time.split(' ');
			const month = date[0].split('-')[1];
			const day = date[0].split('-')[2];
			const hour = date[1].split(':')[0];
			const min = date[1].split(':')[1];
			return month + '月' + day + '日 ' + hour + ':' + min;
		},
		pay(list) {
			var goodsList = [];
			let totalCount = 0;
			let totalPrice = 0;
			list.productInfo.forEach((item, index) => {
				if (item.isSample == 0 && item.preSaleFlag == 0) {
					if (item.isSuit && item.show !== 2) {
						totalCount += item.suitCount;
						totalPrice += item.suitRealAmount;
					} else if (item.show !== 2) {
						totalCount += item.productsCount;
						totalPrice += item.productsCount * item.productDiscountPrice;
					}
					goodsList.push({
						specificationId: item.specificationId,
						productsCount: item.productsCount,
						hasActive: true,
						myOrder: 1,
						orderId: list.orderId,
						buyComment: list.buyerInfo.buyerComment
					});
				} else if (item.preSaleFlag == 1) {
					const afterPaymentTime = this.getAfterPaymentTime(list.productInfo[0], list.preSaleAfterPaymentEndTime, list);
					totalCount += item.productsCount;
					totalPrice += item.productsCount * item.productDiscountPrice;
					goodsList.push({
						specificationId: item.specificationId,
						productsCount: item.productsCount,
						myOrder: 1,
						orderId: list.orderId,
						buyComment: list.buyerInfo.buyerComment,
						preSaleOrderStatus: list.orderPreSaleStatus,
						finalPay: list.retainage,
						deposit: list.deposit,
						preSaleFlag: 1,
						afterPaymentTime: afterPaymentTime,
						preSaleDeliveryTimeText: this.deliveryTime(list)
					});
				}
			});
			console.log(goodsList);
			uni.setStorageSync('carGoodsList', goodsList);
			let couponPrice = 0;
			if (list.couponPrice != null) {
				couponPrice = list.couponPrice;
			}
			let logisticsCost = 0;
			if (list.logisticsCost > 0) {
				logisticsCost = list.logisticsCost;
			}
			const item = {
				productInfo: list.productInfo,
				discountAmount: list.discountAmount,
				couponAmount: couponPrice,
				couponName: list.couponName,
				couponPacleName:list.couponPacleName,
				amount: list.realAmount,
				expressFee: logisticsCost,
				preSaleType: list.productInfo[0].preSaleType,
				totalCount: totalCount,
				totalPrice: totalPrice
			};
			uni.setStorageSync('productList', item);
			uni.navigateTo({
				url: '../submitOrder/submitOrder'
			});
		},
		swichMenu: async function(current) {
			//点击其中一个 tab
			if (this.currentTab == current) {
				return false;
			} else {
				this.searchKey = '';
				this.progressFlg = true;
				this.currentTab = current;
				this.setScrollLeft(current);
				if (this.currentTab !== 6) {
					this.orderList = []; // 先置空列表,显示加载进度
				} else {
					this.postSaleList = [];
				}

				this.mescroll.resetUpScroll(); // 再刷新列表数据
			}
		},
		swiperChange: async function(e) {
			let index = e.target.current;
			this.setScrollLeft(index);
			this.currentTab = index;
		},
		setScrollLeft: async function(tabIndex) {
			let leftWidthSum = 0;
			for (var i = 0; i <= tabIndex; i++) {
				let nowElement = await this.getWidth('tabNum' + i);
				if (nowElement) {
					leftWidthSum = leftWidthSum + nowElement.width;
				}
			}
			let winWidth = uni.getSystemInfoSync().windowWidth;
			this.scrollLeft = leftWidthSum > winWidth ? leftWidthSum - winWidth : 0;
		},

		getWidth: function(id) {
			//得到元素的宽高
			return new Promise((res, rej) => {
				uni.createSelectorQuery()
					.select('#' + id)
					.fields(
						{
							size: true,
							scrollOffset: true
						},
						data => {
							res(data);
						}
					)
					.exec();
			});
		},
		loadMore: function(tabIndex) {
			this.getDateList(tabIndex);
		},
		getDateList: function(tabIndex) {
			for (var i = 0; i < 20; i++) {
				var entity = this.tabs[tabIndex].name + this.swiperDateList[tabIndex].length;
				this.swiperDateList[tabIndex].push(entity);
			}
		}
	}
};
</script>
<style lang="scss">
.suitItem {
	width: 100%;
	float: right;
	background-color: #ffffff;
}
.suitItem {
	.suitProduct:first-of-type {
		border-top: 1px solid #f2f2f2;
	}
	.suitProduct:last-of-type {
		border-bottom: 1px solid #f2f2f2;
	}
}
.suitProduct {
	width: 80% !important;
	float: right;
	border-left: 1px solid #f2f2f2;
}
.b-bottom {
	border-bottom: 1px solid #f2f2f2;
}
.imgMark {
	position: absolute;
	width: 100rpx !important;
	height: 100rpx !important;
	top: 0px;
	left: 12rpx;
	z-index: 100;
}
.progress {
	display: flex;
	top: 0;
	z-index: 9999999;
	width: 100%;
}
.container {
	padding-bottom: env(safe-area-inset-bottom);
	overflow: hidden;
	height: 100%;
	width: 100%;
}
/deep/ .uni-scroll-view::-webkit-scrollbar {
	/* 隐藏滚动条，但依旧具备可以滚动的功能 */
	display: none;
}
scroll-view [style*='overflow']::-webkit-scrollbar {
	display: none;
}
.top-tabs-view {
	width: 100%;
	box-sizing: border-box;
	display: flex;
	align-items: center;
	justify-content: space-between;
	z-index: 9999;
	box-shadow: 0 0 4rpx #e5e5e5;
	white-space: nowrap;
	height: 90rpx;
	position: fixed;
	left: 0;
	background: #fff;
	.tabs-item-wrap {
		display: inline-block;
		white-space: nowrap;
		height: 90rpx;
		width: 20%;
		.tabs-item {
			margin-left: 38rpx;
			margin-right: 35rpx;
			position: relative;
			height: 100%;
			display: flex;
			align-items: center;
			justify-content: center;
			.tabs-item-txt {
				height: 90rpx;
				line-height: 90rpx;
				font-size: 28rpx;
				font-weight: 400;
				color: #333333;
			}
			.tabs-item-bottom {
				position: absolute;
				bottom: 0rpx;
				width: 120rpx;
				height: 4rpx;
				left:calc(50% - 60rpx)
			}
		}
		.tabs-item-act {
			.tabs-item-txt {
				//color:  $themeColor;
			}
			.tabs-item-bottom {
				//background:  $themeColor;
			}
		}
	}
}
.tui-order-list {
	margin-top: 80rpx;
	// margin-top: 192rpx;
}

.swiper-box-list {
	flex: 1;
	width: 100%;
	height: auto;
}
.swiper-one-list {
	height: 100%;
	width: 100%;
}

.swiper-one-list .swiper-list-entity {
	width: 100%;

	height: 112upx;

	text-align: center;

	display: flex;

	flex-wrap: wrap;

	align-items: center;

	justify-content: center;
}
.search-header-box {
	width: 100%;
	background: #fff;
	position: fixed;
	z-index: 99998;
	left: 0;
	top: 0;
	margin-top: 91rpx;
}
.search-header {
	display: flex;
	align-items: center;
	padding: 20rpx 20rpx;
	background: #fff;
	// margin-bottom: 20rpx;
}
.search-searchbox {
	flex: 1;
	height: 60rpx;
	border-radius: 30rpx;
	font-size: 24rpx;
	background: $borderColor;
	padding: 6rpx 20rpx;
	box-sizing: border-box;
	color: #999;
	display: flex;
	align-items: center;
	overflow: hidden;
}
.search-input {
	text-align: left !important;
	margin-left: 12rpx;
	width: 100% !important;
	background-color: $borderColor !important;
	.uni-input-input {
		width: 100%;
	}
}
.search-text {
	font-size: 32rpx;
	color: #444;
	margin: 0 20rpx 0 30rpx;
	color: $red;
}
.search-search-text {
	padding-left: 16rpx;
}
.search-search-key {
	max-width: 80%;
	height: 100%;
	padding: 0 16rpx;
	margin-left: 12rpx;
	display: flex;
	align-items: center;
	border-radius: 15px;
	background: rgba(0, 0, 0, 0.5);
	color: #fff;
}
.search-key-text {
	box-sizing: border-box;
	padding-right: 12rpx;
	font-size: 12px;
	line-height: 12px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.tui-order-item {
	border-top: 16rpx solid #f5f5f5;
	overflow: hidden;
	position: relative;
	.red {
		color: $red;
	}
}
.tui-goods-title {
	width: 100%;
	font-size: 28rpx;
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.tui-order-status {
	color: #888;
	font-size: 26rpx;
}

.tui-goods-item {
	width: 100%;
	padding: 20rpx 30rpx;
	box-sizing: border-box;
	display: flex;
	justify-content: space-between;
	position: relative;
	background-color: #ffffff;
}

.tui-goods-img {
	width: 180rpx;
	height: 180rpx;
	display: block;
	flex-shrink: 0;
	border-radius: 8rpx;
	image {
		border-radius: 8rpx;
	}
}

.tui-goods-center {
	flex: 1;
	padding: 20rpx 8rpx;
	box-sizing: border-box;
}

.tui-goods-name {
	max-width: 310rpx;
	word-break: break-all;
	overflow: hidden;
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	font-size: 26rpx;
	line-height: 32rpx;
}

.tui-goods-attr {
	font-size: 22rpx;
	color: #888888;
	line-height: 32rpx;
	padding-top: 20rpx;
	word-break: break-all;
	overflow: hidden;
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
}

.tui-price-right {
	text-align: right;
	font-size: 24rpx;
	color: #888888;
	line-height: 30rpx;
	padding-top: 20rpx;
}

.tui-color-red {
	color: #e41f19;
	padding-right: 30rpx;
}

.tui-goods-price {
	width: 100%;
	display: flex;
	align-items: flex-end;
	justify-content: flex-end;
	font-size: 24rpx;
}

.tui-size-24 {
	font-size: 24rpx;
	line-height: 24rpx;
}

.tui-price-large {
	font-size: 32rpx;
	line-height: 30rpx;
	font-weight: 500;
}

.tui-order-btn {
	width: 100%;
	display: flex;
	align-items: center;
	justify-content: flex-end;
	background: #fff;
	padding: 10rpx 30rpx 20rpx;
	box-sizing: border-box;
}

.tui-btn-ml {
	margin-left: 20rpx;
}
.b-bottom-none {
	.tui-list-cell::after {
		border-bottom: none;
	}
}
</style>
